package com.songyang.blog.common.lang;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {

    // 0成功，-1失败
    private int status;//状态码
    private String msg;//临时消息返回给前端
    private Object data;//数据
    private String action;//如果为空前端不进行跳转，如果不为空前端跳转url为action的链接

    public static Result success() {
        return Result.success("操作成功", 0);
    }

    public static Result success(Object data) {
        return Result.success("操作成功", data);
    }
    public static Result success(String msg) {
        return Result.success(msg, null);
    }


    public static Result success(String msg, Object data) {
        Result result = new Result();
        result.status = 0;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static Result fail(String msg) {
        Result result = new Result();
        result.status = -1;
        result.data = null;
        result.msg = msg;
        return result;
    }

    public Result action(String action) {
        this.action = action;
        return this;
    }


}
